﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FFS.Model;
using FFS.BLL;

namespace FFS
{
    public partial class frmSystemLog : Form
    {
        public frmSystemLog()
        {
            InitializeComponent();
        }

        SystemLogInfo sysLog = new SystemLogInfo();
        List<SystemLogInfo> logList = new List<SystemLogInfo>();
        SystemLogService logService = new SystemLogService();

        private void BindListView(List<SystemLogInfo> sysLogList)
        {
            this.listView_SystemLoginLog.Items.Clear();
            foreach (SystemLogInfo log in sysLogList)
            {
                string[] str = new string[5];
                str[0] = log.LoginUserName;
                str[1] = log.ActionType;
                str[2] = log.ActionLog;
                str[3] = log.InputDate.ToString("yyyyMMdd HHmmss");
                str[4] = log.InputUser;
                ListViewItem item = new ListViewItem(str);
                this.listView_SystemLoginLog.Items.Add(item);
            }
        }

        private void frmSystemLog_Load(object sender, EventArgs e)
        {
            this.cmb_searchItem.SelectedIndex = 0;
            this.BindListView(logService.ManageSystemLog().GetSystemLogByActionType("Login",""));
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            string searchCondition = " and  1=1 ";
            if (this.cmb_searchItem.SelectedIndex == 0)
            {
                searchCondition = " and input_user like N'%" + this.txt_searchCondition.Text.Trim() + "%'";
            }
            else if (this.cmb_searchItem.SelectedIndex == 1)
            {
                searchCondition = " and ActionType like N'%" + this.txt_searchCondition.Text.Trim() + "%' ";
            }
            else if (this.cmb_searchItem.SelectedIndex == 2)
            {
                searchCondition = " and ActionLog like N'%" + this.txt_searchCondition.Text.Trim() + "%' ";
            }

            this.BindListView(logService.ManageSystemLog().GetSystemLogByActionType("login",searchCondition));
        }
    }
}
